#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""
@author:hengk
@contact: hengk@foxmail.com
@datetime:2019-11-04 10:53
"""
import numpy as np
import cv2

class Image(object):
    def __init__(self):

        self.random_h_flip_ = True
        self.random_h_flip_p_ = 0.5
        self.random_v_flip_ = True
        self.random_v_flip_p_ = 0.5

    def apply(self,img):
        p = []
        funcs = []

        if self.random_h_flip_ == True:
            p.append(self.random_h_flip_p_)
            funcs.append(self.h_flip)
        if self.random_v_flip_ == True:
            p.append(self.random_v_flip_p_)
            funcs.append(self.v_flip)

        if len(p) == 0:
            return img

        noise_func = np.random.choice(funcs, p=p)

        return noise_func(img)

    def h_flip(self,image):
        """
        对图片进行水平翻转
        :param image:
        :return:
        """
        return cv2.flip(image, 1)

    def v_flip(self,image):
        """
        对图片进行垂直旋转
        :param image:
        :return:
        """
        return cv2.flip(image,0)